<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link rel="stylesheet" href="../../../../src/css/common/reset.css">
    <link rel="stylesheet" href="../../../../src/css/common/grid.css">
    <link rel="stylesheet" href="//at.alicdn.com/t/font_335449_704tmvg9nqc.css">
    <style>
        .demo{
            width:300px;
            min-height: 400px;
            margin:0 auto;
            padding:10px;
            border: 1px solid #ebebeb;
        }

        .star-item{
            display: inline-block;
            margin-left: 5px;
        }

        .star-item .star-list{
            display: inline-block;
            cursor: pointer;
            color:#333;
            letter-spacing:3px;
        }
    </style>
</head>
<body>
    <div class="demo clearfix">

        <div>
            <ul class="star-item">
                <li class="star-list iconfont icon-star0 icon-start1"></li>
                <li class="star-list iconfont icon-star0 icon-start1"></li>
                <li class="star-list iconfont icon-star0 icon-start1"></li>
                <li class="star-list iconfont icon-star0 icon-start1"></li>
                <li class="star-list iconfont icon-star0 icon-start1"></li>
            </ul>
            <input type="hidden" name="starVal" value="5">
        </div>


    </div>

</body>
<script src="../../../../src/lib/jquery.min.js"></script>
<script>
    $(function(){
        $('.star-list').on({
            mouseenter:function(){
                var num = $(this).index();
                var box = $(this).parent('.star-item').find('.star-list');
                box.each(function(index,item){
                    if(index<=num){
                        $(item).addClass('icon-start1');
                    }else{
                        $(item).removeClass('icon-start1');
                    }
                })
            },
            click:function(){
                var num = $(this).index();
                $(this).parent('.star-item').attr('data-val',num + 1);
                $("input[name='starVal']").val(num+1);
            }
        });

        $('.star-item').on('mouseleave',function(){
            var val = $(this).attr('data-val');
            var box = $(this).find('.star-list');
            if(val){
                box.each(function(index,item){
                    if(index<val){
                        $(item).addClass('icon-start1');
                    }else{
                        $(item).removeClass('icon-start1');
                    }
                })
            }else{
                box.addClass('icon-start1');
            }
        });
    })
</script>
</html>